Waiter Tips (Case Study)

The food server of a restaurant recorded data about the tips given to the waiters for serving the food. The data recorded by the food server is as follows:

total_bill: Total bill in dollars including taxes

tip: Tip given to waiters in dollars

sex: gender of the person paying the bill

smoker: whether the person smoked or not

day: day of the week

time: lunch or dinner

size: number of people in a table

So this is the data recorded by the restaurant. Based on this data, our task is to find the factors affecting waiter tips and train a machine learning model to predict the waiter’s tipping.

Waiter Tips Prediction using Python

Waiter Tips Analysis

Let’s have a look at the tips given to the waiters according to:

the total bill paid

number of people at a table and the day of the week:

Now let’s have a look at the tips given to the waiters according to:

the total bill paid

the number of people at a table

and the gender of the person paying the bill:

Now let’s have a look at the tips given to the waiters according to:

the total bill paid the number of people at a table and the time of the meal:

Now let’s see the tips given to the waiters according to the days to find out which day the most tips are given to the waiters:

According to the visualization above, on Saturdays, most tips are given to the waiters.

Now let’s look at the number of tips given to waiters by gender of the person paying the bill to see who tips waiters the most:

According to the visualization above, most tips are given by men. Now let’s see if a smoker tips more or a non-smoker:

According to the visualization above, non-smoker tips waiters more than smokers. Now let’s see if most tips are given during lunch or dinner:

According to the visualization above, a waiter is tipped more during dinner.

So this is how we can analyze all the factors affecting waiter tips. Now in the section below, I will take you through how to train a machine learning model for the task of waiter tips prediction.

Waiter Tips Prediction Model

Before training a waiter tips prediction model, I will do some data transformation by transforming the categorical values into numerical values:

Now I will split the data into training and test sets:

Now below is how we can train a machine learning model for the task of waiter tips prediction using Python:

Now let’s test the performance of this model by giving inputs to this model according to the features that we have used to train this model: